﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SuperSerialization.Tree
{
    /// <summary>
    /// A node representing a literal value.
    /// </summary>
    class LiteralNode : Node
    {
        /// <summary>
        /// The literal value of the node.
        /// </summary>
        public object Value;

        /// <summary>
        /// Constructs a new literal node.
        /// </summary>
        public LiteralNode() { }

        /// <summary>
        /// Constructs a new literal node.
        /// </summary>
        /// <param name="value">The node's value.</param>
        public LiteralNode(object value)
        {
            this.Value = value;
        }

        public override void Accept(TreeVisitor.AbstractVisitor visitor)
        {
            visitor.VisitLiteral(this);
        }
    }

    /// <summary>
    /// Represents a string literal.
    /// </summary>
    class StringNode : LiteralNode
    {
        /// <summary>
        /// Creates a new string literal node.
        /// TODO: Get rid of this class and use the base class. This can be a separate constructor.
        /// </summary>
        /// <param name="value">The string value.</param>
        public StringNode(string value)
        {
            value = value.Replace("\"", "\\\"");
            this.Value = value;
        }
    }
}
